home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Best Binary Search Tree Balance Algo?
- Date: 10 Mar 1996 13:15:57 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4hvgqdINN598@keats.ugrad.cs.ubc.ca>
- References: <4hqvc5$p9k@solaria.cc.gatech.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4hqvc5$p9k@solaria.cc.gatech.edu>,
- David Mitchell <bigdave@cc.gatech.edu> wrote:
- >I would like to know what the run-time of the best binary search tree
- >balance algorithm is. (e.g. O(n^2), O(n lg n), etc.).
-
- This question needs a lot more qualification. First of all, algorithms which
- balance trees (Red-Black, AVL) do so incrementally.
-
- The cost of building a Red-Black or AVL tree from an unsorted list is O(n log
- n). Thus a rebalancing operation on an existing binary tree should have a
- complexity no worse than a wholesale insertion of all of the elements of the
- tree into one of these data structures, else this method becomes more viable.
-
- The incremental rebalancing operations in these algorithms add a O(log n) cost
- to an insertion or deletion operation, since the rebalancing operation requires
- that you look at only the nodes which dominate the newly inserted node. If
- memory serves me, in the AVL algorithm, you look for a ``pivot'' node in the
- path that leads to the root node. You then do a rebalancing operation which
- involves checking a small number of cases. Since the search for the insertion
- point is O(log n) in the first place, the rebalancing adds nothing to the
- asymptotic cost of the insertion, other than worsen the coefficient.
-
- >I wish there was an algorithms newsgroup, but it seems as if C/C++
- >programmers know better algorithms than just about anyone else.
-
- There are other sources for research besides newsgroups. These kinds of basic
- algorithms are discussed in a myriad of computer science textbooks, papers,
- journals, etc. Though most of the papers would have to be pretty old for
- research about this particular topic!
-
- >If you could send the code too, or just an algorithm description that
- >would be great. The important part is that it must be the fastest known so
- >far.
-
- I believe that a balanced tree can be constructed from a _sorted_ list in O(n),
- using a bottom-up algorithm. I doubt you could do it faster than this!
- --
-
-